/*
  Simple DirectMedia Layer
  Copyright (C) 1997-2020 Sam Lantinga <slouken@libsdl.org>

  This software is provided 'as-is', without any express or implied
  warranty.  In no event will the authors be held liable for any damages
  arising from the use of this software.

  Permission is granted to anyone to use this software for any purpose,
  including commercial applications, and to alter it and redistribute it
  freely, subject to the following restrictions:

  1. The origin of this software must not be misrepresented; you must not
     claim that you wrote the original software. If you use this software
     in a product, an acknowledgment in the product documentation would be
     appreciated but is not required.
  2. Altered source versions must be plainly marked as such, and must not be
     misrepresented as being the original software.
  3. This notice may not be removed or altered from any source distribution.
*/
#include "../../SDL_internal.h"

#if SDL_VIDEO_DRIVER_VIVANTE

#include "SDL_vivanteplatform.h"

#ifdef VIVANTE_PLATFORM_GENERIC

#ifdef LOONGSON
#define WINDOW_WIDTH    1024
#define WINDOW_HEIGHT    768

void _ModuleConstructor(void);

struct mode_arg
{
    unsigned int choosed_width;
    unsigned int choosed_height;
    unsigned int bpp;
    unsigned long addr;
    unsigned int horiz;
    unsigned int vert;
};

#define CMD_SET_MOD     0x1001
#define CMD_DC_ADDR_GET 0x100E
#define CMD_3d_ADDR_GET 0x100F
#endif

int
VIVANTE_SetupPlatform(_THIS)
{
#ifdef LOONGSON
    int ls_demo_fd = 0;
    struct mode_arg setmode_arg;

    _ModuleConstructor();
    ls_demo_fd = open("/dev/kms", 2, 0);
    if(ls_demo_fd < 0)
    {
        printf("open vivante dev error fd:%d\r\n", ls_demo_fd);
        return -1;
    }

    setmode_arg.addr = ioctl(ls_demo_fd, CMD_3d_ADDR_GET, NULL);
    setmode_arg.choosed_width = WINDOW_WIDTH;
    setmode_arg.choosed_height = WINDOW_HEIGHT;
    setmode_arg.bpp = 32;
    setmode_arg.horiz = 1;
    setmode_arg.vert = 1;
    ioctl(ls_demo_fd, CMD_SET_MOD, (long)&setmode_arg);
#endif
    return 0;
}

char *VIVANTE_GetDisplayName(_THIS)
{
    return NULL;
}

void
VIVANTE_UpdateDisplayScale(_THIS)
{
}

void
VIVANTE_CleanupPlatform(_THIS)
{
}

#endif /* VIVANTE_PLATFORM_GENERIC */

#endif /* SDL_VIDEO_DRIVER_VIVANTE */

/* vi: set ts=4 sw=4 expandtab: */
